package com.study.socket;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/9/27 19:16
 */
public class Client
{
    public static void main(String[] args) throws IOException
    {
        SocketChannel open = SocketChannel.open(new InetSocketAddress("127.0.0.1", 9898));
        FileChannel channel = FileChannel.open(Paths.get("E:\\GoogleDownLoad\\timg.jpg"), StandardOpenOption.READ);
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);

        while (channel.read(byteBuffer) != -1)
        {
            byteBuffer.flip();
            open.write(byteBuffer);
            byteBuffer.clear();
        }
        channel.close();
        open.close();
    }
}
